﻿using StoryMaker.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace StoryMaker.Application
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : System.Windows.Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            StoryMaker.Plugins.Startup.Instance.LoadAssemblies();
        }
        private void TemplateShape_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ShapeControl control = sender as ShapeControl;
            if (control != null)
            {
                StoryShape shape = control.StoryShape;
                if (shape != null && e.LeftButton == MouseButtonState.Pressed)
                {
                    DragDrop.DoDragDrop(control,
                                         new ShapeDataObject(shape),
                                         DragDropEffects.Copy);
                }
            }
        }

        private void CanvasItemControl_Drop(object sender, System.Windows.DragEventArgs e)
        {
            ItemsControl control = sender as ItemsControl;
            if (control != null)
            {
                StoryShape shape = e.Data.GetData(ShapeDataObject.ShapeFormat) as StoryShape;
                if (shape != null)
                {
                    StoryShape newStoryShape = (StoryShape)shape.Clone();
                    Point position = e.GetPosition(control);
                    newStoryShape.Top = position.Y - shape.Height / 2;
                    newStoryShape.Left = position.X - shape.Width / 2;
                    ((StoryMaker.Common.Page)control.DataContext).Shapes.Add(newStoryShape);
                }
            }
        }
    }
}
